package day18.tarena.Thred;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ProgressBar extends Thread implements ActionListener{
	JProgressBar jdt = new JProgressBar(JProgressBar.HORIZONTAL);
	int i =0;
	public void run() {
		for (int i = 0; i <= 100; i++) {
			jdt.setValue(i);
			try {
				Thread.sleep(50);
				jdt.setStringPainted(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public void actionPerformed(ActionEvent e) {
		String comm = e.getActionCommand();
		if("开始下载".equals(comm)){
			start();
		}else if("暂停下载".equals(comm)){
			
		}else {
			System.exit(0);
		}
	}

	public ProgressBar(){
    	JFrame jf = new JFrame("文件下载管理器");
    	jf.setLayout(new FlowLayout());
    	JButton jb1 = new JButton("开始下载");
    	JButton jb2 = new JButton("暂停下载");
    	JButton jb3 = new JButton("退出下载");
    	jb1.addActionListener(this);
    	jb2.addActionListener(this);
    	jb3.addActionListener(this);
    	jf.add(jb1);
    	jf.add(jb2);
    	jf.add(jb3);
    	jf.add(jdt);
		jf.setLocation(400,400);
		jf.pack();
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	public static void main(String[] args) {
		new ProgressBar();

	}

	
}
